package com.kd.juhaowan.ui;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.kd.juhaowan.R;
import com.kd.juhaowan.http.api.ChangePwdOldApi;
import com.kd.juhaowan.http.model.GameModel;
import com.kd.juhaowan.http.model.HttpData;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallbackProxy;
import com.hjq.toast.ToastUtils;

import butterknife.BindView;
import butterknife.OnClick;

public class PwdChangeByPwdActivity extends BaseActivity {





    @BindView(R.id.activity_title)
    TextView titleView;

    @BindView(R.id.pwdpwdold_old)
    EditText oldPwd;
    @BindView(R.id.pwdpwdold_new)
    EditText newPwd;
    @BindView(R.id.pwdpwdold_confirm)
    EditText confirmPwd;





    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        titleView.setText("修改密码");
//        setContentView(R.layout.activity_account_login);

    }

    @Override
    protected void reInitDate() {

    }

    @OnClick(R.id.actvity_back)
    public void onBackClick(){
        finish();
    }
    @OnClick(R.id.pwdpwd_forget)
    public void onPhoneClick(){
        startActivity(new Intent(this,PwdChangeByPhoneActivity.class));
        finish();
    }
    @OnClick(R.id.login_confirm)
    public void onConfirmClick(){
        String oldString = oldPwd.getText().toString().trim();
        String newString = newPwd.getText().toString().trim();
        String confirmString = confirmPwd.getText().toString().trim();
        if(TextUtils.isEmpty(oldString)){
            ToastUtils.show("请输入原密码");
        }else if(TextUtils.isEmpty(newString)){
            ToastUtils.show("请输入新密码");
        }else if(TextUtils.isEmpty(confirmString)){
            ToastUtils.show("请确认新密码");
        }else if (!newString.equals(confirmString)){
            ToastUtils.show("两次密码不一致");
        }else{
            EasyHttp.post(this).api(new ChangePwdOldApi(oldString,newString,confirmString)).request(new HttpCallbackProxy<HttpData<GameModel>>(this){
                @Override
                public void onHttpSuccess(HttpData<GameModel> result, boolean cache) {
                    super.onHttpSuccess(result, cache);
                    ToastUtils.show("修改成功");
                    manager.writeAutoLogin(false);
                    startActivity(new Intent(PwdChangeByPwdActivity.this,LoginAccountActivity.class));
                    finish();
                }
            });
        }
    }
    @Override
    protected int getViewLayoutResourceId() {
        return R.layout.activity_pwdpwd;
    }




}
